package cn.wolfcode.web.controller;

import cn.wolfcode.qo.CustomerReportQuery;
import cn.wolfcode.service.CustomerReportService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 杨兴健
 * @Date 2020/7/23 17:16
 */
@Controller
@RequestMapping("/customerReport")
public class CustomerReportController {

    @Autowired
    private CustomerReportService customerReportService;

    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") CustomerReportQuery qo, Model model) {
        PageInfo<HashMap> reports = customerReportService.selectForList(qo);
        model.addAttribute("pageInfo", reports);
        return "/customerReport/list";
    }

    @RequestMapping("/listBar")
    public String listBar(@ModelAttribute("qo") CustomerReportQuery qo, Model model) {
        Map<String, String> listMap = customerReportService.selectAllBar(qo);
        model.addAttribute("groupTypes", listMap.get("groupType"));
        model.addAttribute("numbers", listMap.get("number"));
        return "/customerReport/listBar";
    }

    @RequestMapping("/listPie")
    public String listPie(@ModelAttribute("qo") CustomerReportQuery qo, Model model) {
        Map<String, String> listMap = customerReportService.selectAllPie(qo);
        model.addAttribute("groupTypes", listMap.get("groupType"));
        model.addAttribute("numbers", listMap.get("number"));
        return "/customerReport/listPie";
    }


}
